from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

# 打开浏览器
driver = webdriver.Chrome()
# 访问的网页
driver.get('http://192.168.1.25/crm')
driver.implicitly_wait(30)
# 最大化窗口
driver.maximize_window()

username = '杨应科'
password = '123456'

# 定位器
username_locator = (By.NAME,'name')
password_locator = (By.NAME,'password')
dl_locator = (By.NAME,'submit')
dianji_gd_locator = (By.XPATH,'/html/body/div[1]/div/div/div[2]/ul[1]/li[9]/a')
dianji_zlx_locator = (By.XPATH,'/html/body/div[1]/div/div/div[2]/ul[1]/li[9]/ul/li[4]/a')
dainji_xx_locator = (By.ID,'send')
leirong_locator = (By.NAME,'content')
dianji_quxiao_locator = (By.CSS_SELECTOR,'#dialog-message-send > form > table > tfoot > tr > td:nth-child(2) > input:nth-child(2)')


# 执行
driver.find_element(*username_locator).send_keys(username)
driver.find_element(*password_locator).send_keys(password)
sleep(0.5)
driver.find_element(*dl_locator).click()
sleep(1)
driver.find_element(*dianji_gd_locator).click()
driver.find_element(*dianji_zlx_locator).click()
driver.find_element(*dainji_xx_locator).click()
driver.find_element(*leirong_locator).send_keys('自动化')
sleep(2)
driver.find_element(*dianji_quxiao_locator).click()
sleep(3)
driver.quit()